import time
import requests
import re
import os
import json
import datetime
import requests
from lxml import etree

def main(name):
    url='http://jwgl.sdust.edu.cn/jsxsd/kbcx/kbxx_classroom_ifr'
    headers={
        'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36 Edg/95.0.1020.44',
        "Cookie": "JSESSIONID=E8C8F3255FDDB2971C52D82CBC7CBBA0",
    }
    page_text = requests.get(url=url,headers=headers).content.decode('utf-8')
    tree = etree.HTML(page_text)
    jiaoshilist = tree.xpath('//*[@id="kbtable"]/tr')
    dic = dict()
    for i in range(2,644):
        jiaoshi = jiaoshilist[i].xpath('./td')
        jiaoshiname = jiaoshilist[i].xpath('./td[1]/nobr/text()')[0]
        dic[jiaoshiname]=[]
        for day in range(1,32,5):
            ts=[]
            for j in range(day,day+5):
                kechenglist = jiaoshi[j].xpath('./nobr/div')
                if len(kechenglist) != 0:
                    z=[]
                    for k in kechenglist:
                        kecheng = k.xpath('./text()')[1].split('\n')[-1]
                        z.append(kecheng)
                    ts.append(z)
                else:
                    ts.append(['无课'])
            dic[jiaoshiname].append(ts)

    return dic[name]